package com.ruoyi.develop.finance.financeAp.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.develop.goodsSaledo.domain.GoodsSaledo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.finance.financeAp.domain.FinanceAp;
import com.ruoyi.develop.finance.financeAp.service.IFinanceApService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应付账单Controller
 * @author lmm
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/financeAp/financeAp")
public class FinanceApController extends BaseController {
    @Autowired
    private IFinanceApService financeApService;

    /**
     * 查询应付账单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:FinanceAp:query')")
    @GetMapping("/list")
    public TableDataInfo list(FinanceAp entity) {
        startPage();
        List<FinanceAp> list = financeApService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出应付账单详细信息
     */
    @Log(title = "导出应付账单列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult exportData(HttpServletRequest request, HttpServletResponse response, FinanceAp entity) {
        if(StringUtils.isBlank(entity.getSupplierId())){
            return AjaxResult.error("供应商不能为空");
        }
        financeApService.exportData(request,response,entity);
        return AjaxResult.success("导出成功");
    }

    /**
     * 获取应付账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:FinanceAp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(financeApService.selectById(id));
    }

    /**
     * 新增应付账单
     */
    @PreAuthorize("@ss.hasPermi('develop:FinanceAp:add')")
    @Log(title = "应付账单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FinanceAp entity) {
        return toAjax(financeApService.insert(entity));
    }

    /**
     * 修改应付账单
     */
    @PreAuthorize("@ss.hasPermi('develop:FinanceAp:edit')")
    @Log(title = "应付账单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FinanceAp entity) {
        return toAjax(financeApService.update(entity));
    }

    /**
     * 删除应付账单
     */
    @PreAuthorize("@ss.hasPermi('develop:FinanceAp:remove')")
    @Log(title = "应付账单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(financeApService.deleteByIds(ids));
    }
}
